import QtQuick 2.0
import org.qtproject.qtquick 1.0

import "qrc:/js/resources/Constants.js" as Constant

import "../delegate"
import "../common"
import "../page"
import "../message"

Item {
    id: id_conversationDelegate
    width: parent.width
    height: heightText

    property var msgId: messageId
    property string txtMessage: message
    property string avatarImage;
    property var txtTime: createdTime
    property bool deliveredMsg: deliveredMessage
    property bool combinedMessage: isCombinedMessage

    property var uid: Constant.m_uidActive

    property bool isSent:  uid === senderId ? true : false
    property int heightText: uid === senderId ? id_messageSent.height : id_messageReceived.height


    Row {
        anchors.right: parent.right
        visible: isSent

        ErrorMessage {
            id: id_errorMessage
            visible: false
        }

        TimeMessage {
            id: id_timeSent
            anchors.verticalCenter: parent.verticalCenter
        }

        MessageSent {
            id: id_messageSent
        }

    }

    Row {
        anchors.left: parent.left
        visible: !isSent

//        ItemImageChat {
//            id: id_avatar
//            anchors.verticalCenter: parent.verticalCenter

//            m_width: 50 * m_ratio
//            m_height: 50 * m_ratio

//            visible: combinedMessage
//        }

        Item {
            id: id_avatar
            width: 60 * m_ratio
            height: 60 * m_ratio
            anchors.verticalCenter: parent.verticalCenter

            visible: combinedMessage

            Image {
                id: id_avatarUrl


                source: Constant.m_avatarUrlFriendActive

                height: parent.width
                width: parent.height

            }

            ImageTranparent {
                m_width: parent.width
                m_height: parent.height
                color: "transparent"
            }
        }


        MessageReceived {
            id: id_messageReceived

            anchors.verticalCenter: parent.verticalCenter
        }

        TimeMessage {
            id: id_timeReceived
            anchors.verticalCenter: parent.verticalCenter
        }
    }
}
